from django.db import models
from django.db.models import DO_NOTHING

from apps.company.models import Company
from apps.index.models import JobCategory
from apps.resume.models import UserResume
from apps.users.models import User


class Position(models.Model):
    """职位表"""

    job_category = models.CharField(max_length=16, verbose_name='一级职位类别')
    position_name = models.CharField(max_length=16, verbose_name='二级职位类别')
    department = models.CharField(max_length=20, verbose_name='部门')
    job_nature = models.CharField(max_length=20, verbose_name='工作性质')
    salary_min = models.CharField(max_length=5, verbose_name='最低工资')
    salary_max = models.CharField(max_length=5, verbose_name='最高工资')
    work_address = models.CharField(max_length=16, verbose_name='工作城市')
    work_year = models.CharField(max_length=16, verbose_name='工作经验')
    education = models.CharField(max_length=16, verbose_name='学历要求')
    position_advantage = models.CharField(max_length=50, verbose_name='职位诱惑')
    position_detail = models.CharField(max_length=1000, verbose_name='职位描述')
    position_address = models.CharField(max_length=50, verbose_name='工作地址')
    p_email = models.CharField(max_length=50, verbose_name='接收简历邮箱')
    forward_email = models.CharField(max_length=50, verbose_name='伴生邮箱')
    status = models.BooleanField(default=False, verbose_name='当前状态')  # 是否下线
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除 ')
    company = models.ForeignKey(Company, on_delete=DO_NOTHING, verbose_name="所属公司")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_new_position'
        verbose_name = '发布职位表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.position_name


class ReceiveResume(models.Model):
    """已接收简历表"""
    STATUS_CHOICES = (
        (1, '待处理'),
        (2, '已通知面试'),
        (3, '不合适'),
        (4, '自动过滤'),
    )
    resume = models.ForeignKey(UserResume, on_delete=DO_NOTHING, verbose_name="投递用户简历")
    position = models.ForeignKey(Position, on_delete=DO_NOTHING, verbose_name="被投递简历职位")
    status = models.IntegerField(choices=STATUS_CHOICES, default=1, verbose_name='状态')
    is_delete = models.BooleanField(default=False, verbose_name='是否删除')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_rece_resume'
        verbose_name = '接收简历表'
        verbose_name_plural = verbose_name


class CollectPosition(models.Model):
    """已收藏职位表"""

    position = models.ForeignKey(Position, on_delete=DO_NOTHING, verbose_name="被收藏职位")
    user = models.ForeignKey(User, on_delete=DO_NOTHING, verbose_name="收藏的用户")
    is_delete = models.BooleanField(default=False, verbose_name='是否删除')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_collect'
        verbose_name = '收藏职位表'
        verbose_name_plural = verbose_name
